package com.atguigu.gmall.util;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author : ranzlupup
 * @since : 2023/6/6 12:03
 */
public class ThreadPoolUtil {
    private static ThreadPoolExecutor threadPoolExecutor;

    /**
     * 单例模式 懒汉式
     */
    public static ThreadPoolExecutor getThreadPoolExecutor() {
        if (threadPoolExecutor == null) {
            // 线程安全
            synchronized (ThreadPoolUtil.class) {
                if (threadPoolExecutor == null) {
                    threadPoolExecutor = new ThreadPoolExecutor(
                            4,
                            20,
                            100,
                            TimeUnit.SECONDS,
                            new LinkedBlockingDeque<>()
                    );
                }
            }

        }
        return threadPoolExecutor;
    }
}
